//import { numberFormat } from './../utils/numberFormat'

function getBackData(oldObj, backObj) {
    oldObj.num = backObj.paymentBase
    oldObj.scale = backObj.percentage
    oldObj.sum = backObj.amount || ''
    oldObj.ex = backObj.description
}
let priceTable = {
    social: {
        sum: '', // 类型费用
        ex: '', // 说明
        tip: '社保公积金'
    },
    lodging: {
        // 住房
        num: '',
        scale: '',
        ex: '',
        sum: '',
        tip: '住房公积金'
    },
    procreate: {
        // 生育
        num: '',
        scale: '',
        ex: '',
        sum: '',
        tip: '生育保险'
    },
    medical: {
        // 医疗
        num: '',
        scale: '',
        ex: '',
        sum: '',
        tip: '医疗保险'
    },
    jobInjury: {
        // 工伤
        num: '',
        scale: '',
        ex: '',
        sum: '',
        tip: '工伤保险'
    },
    loseJob: {
        // 失业
        num: '',
        scale: '',
        ex: '',
        sum: '',
        tip: '失业保险'
    },
    liveOut: {
        // 养老
        num: '', // 月缴费基数
        scale: '', // 公司部分比例
        ex: '', // 说明
        sum: 0, // 类型费用
        tip: '养老保险' // 项目名称
    },
    basePay: {
        // 基本工资
        ex: '',
        num: '',
        scale: '',
        sum: '',
        tip: '基本工资'
    },
    other: {
        // 其他费用
        num: '',
        ex: '',
        scale: '',
        sum: '',
        tip: '其他费用'
    },
    serviceChange: {
        // 服务费标准
        num: '',
        scale: '',
        ex: '',
        sum: '',
        tip: '服务费标准'
    },
    protect: {
        // 残保金
        num: '',
        scale: '',
        ex: '',
        sum: '',
        tip: '残保金'
    },
    performance: {
        // 绩效
        num: '',
        scale: '',
        ex: '',
        sum: '',
        tip: '绩效'
    },
    subsidy: {
        // 补贴
        num: '',
        scale: '',
        ex: '',
        sum: '',
        tip: '补贴'
    },
    tax: {
        // 税点
        num: '',
        scale: '',
        ex: '',
        sum: '',
        tip: '税点'
    },
    sumCount: {
        // 总计
        ex: '',
        sum: '',
        tip: '总计（元）：'
    }
}

export function decQuotePriceTable(tempOfferDetail, expressionDetail, offerType, offerState) {
    if (tempOfferDetail.length > 0) {
        let len = tempOfferDetail.length,
            offers = tempOfferDetail,
            tempItem = {},
            tempPriceItem = {},
            tempObj = {},
            tempData = {
                datas: [],
                sumPrice: '',
                allSum: '',
                isBuildPrice: false,
                allWorkTxt: '',
                otherWorkTxt: '',
                fullExpressionId: '', // 全勤ID
                absenceExpressionId: '', // 缺勤ID
                allWorkVal: '',
                otherWorkVal: '',
                priceTable: {},
                isDisOfferStus: offerState.state === 5 ? true : false
            }
        for (let i = 0; i < len; i++) {
            tempPriceItem = offers[i]
            if (tempPriceItem.projectCode === '社保公积金') {
                getBackData(priceTable.social, tempPriceItem)
            } else if (tempPriceItem.projectCode === '养老保险') {
                getBackData(priceTable.liveOut, tempPriceItem)
            } else if (tempPriceItem.projectCode === '失业保险') {
                getBackData(priceTable.loseJob, tempPriceItem)
            } else if (tempPriceItem.projectCode === '工伤保险') {
                getBackData(priceTable.jobInjury, tempPriceItem)
            } else if (tempPriceItem.projectCode === '医疗保险') {
                getBackData(priceTable.medical, tempPriceItem)
            } else if (tempPriceItem.projectCode === '生育保险') {
                getBackData(priceTable.procreate, tempPriceItem)
            } else if (tempPriceItem.projectCode === '住房公积金') {
                getBackData(priceTable.lodging, tempPriceItem)
            } else if (tempPriceItem.projectCode === '基本工资') {
                getBackData(priceTable.basePay, tempPriceItem)
            } else if (tempPriceItem.projectCode === '其他费用') {
                getBackData(priceTable.other, tempPriceItem)
            } else if (tempPriceItem.projectCode === '服务费标准') {
                getBackData(priceTable.serviceChange, tempPriceItem)
            } else if (tempPriceItem.projectCode === '税点') {
                getBackData(priceTable.tax, tempPriceItem)
            } else if (tempPriceItem.projectCode === '残保金') {
                getBackData(priceTable.protect, tempPriceItem)
            } else if (tempPriceItem.projectCode === '绩效') {
                getBackData(priceTable.performance, tempPriceItem)
            } else if (tempPriceItem.projectCode === '补贴') {
                getBackData(priceTable.subsidy, tempPriceItem)
            } else if (tempPriceItem.projectCode === '总计（元）：') {
                getBackData(priceTable.sumCount, tempPriceItem)
            }
        }

        for (let i = 0; i < offers.length; i++) {
            tempItem = offers[i]
            tempObj = {
                //amount: numberFormat(tempItem.amount, 2, '.', ','),
                amount: tempItem.amount,
                createDate: tempItem.createDate,
                creater: tempItem.creater,
                description: tempItem.description,
                id: tempItem.id,
                //paymentBase: tempItem.paymentBase === 0 ? '-' : numberFormat(tempItem.paymentBase, 2, '.', ','),
                paymentBase: tempItem.paymentBase,
                percentage: tempItem.percentage === '' ? '-' : tempItem.percentage,
                projectCode: tempItem.projectCode,
                typeCode: tempItem.typeCode,
                updateDate: tempItem.updateDate,
                updater: tempItem.updater
            }

            tempData.datas.push(tempObj)
            if (offerType === 0 || offerType === '0') {
                tempData.isBuildPrice = true
            } else {
                tempData.isBuildPrice = false;
            }
            if (expressionDetail && expressionDetail !== null) {
                tempData.allWorkTxt = expressionDetail.fullExpressionTranslateForShow || '' // 全勤显示文本
                tempData.otherWorkTxt = expressionDetail.absenceExpressionTranslateForShow || '' // 缺勤显示文本
                tempData.allWorkVal = expressionDetail.fullDescription || '' // 下拉显示的值 
                tempData.otherWorkVal = expressionDetail.absenceDescription || '' // 下拉显示的值
                tempData.fullExpressionId = expressionDetail.fullExpressionId || '' // 全勤ID
                tempData.absenceExpressionId = expressionDetail.absenceExpressionId || '' // 缺勤ID
            }/*  else {
                tempData.allWorkTxt = 'aa' // 全勤显示文本
                tempData.otherWorkTxt =  'b' // 缺勤显示文本
                tempData.allWorkVal =  'aa' // 下拉显示的值 
                tempData.otherWorkVal =  'b' // 下拉显示的值
            } */
        }
        tempData.priceTable = priceTable;
        console.log('===================aa');
        console.log(tempData)
        return tempData;
    } else {
        console.log('报价没数据!');
    }
    return [];
}